package service

import (
	"errors"
	dto "goweb/dto"
)

//GetUser 获取用户信息
func GetUser(userID string) (*dto.User, error) {
	db, _ := dto.GetDb()
	defer db.Close()
	var user dto.User
	err := db.QueryRow("select a.user_id userId,b.name from sys_user a left join sys_user_info b on a.user_id=b.user_id where a.user_id=?", userID).Scan(&user.UserID, &user.Name)
	if nil != err || "" == user.UserID {
		return nil, errors.New("用户不存在")
	}
	return &user, nil
}

//GetUserByName 根据名称获取用户信息
func GetUserByName(loginName string, pwd string) (*dto.User, error) {
	db, _ := dto.GetDb()
	defer db.Close()
	var user dto.User
	err := db.QueryRow("select a.user_id userId,b.name from sys_user a left join sys_user_info b on a.user_id=b.user_id where login_name=? and pwd=?", loginName, pwd).Scan(&user.UserID, &user.Name)
	if nil != err || "" == user.UserID {
		return nil, errors.New("用户名或密码错误")
	}
	return &user, nil
}
